package com.xxx.hhh.demo.demo8;

import java.io.*;
import java.net.Socket;

public class UpdateFileRunnable implements Runnable {
    Socket socket;
    UpdateFileRunnable(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        try {
            BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\hhh" + Math.random() +".png"));
            int len;

            while ((len = bis.read()) != -1){
                bos.write(len);
                bos.flush();
            }

            Thread.sleep(2000);

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            bw.write("上传成功");

            bw.close();
            bos.close();

        }catch (Exception e) {
            e.printStackTrace();

        }
    }
}
